<!-- 功能  定时关机弹窗 | 作者：menghao.yan | 邮箱：yxs2615@163.com | 时间：2023年08月24日 14:23:00 -->
<template>
  <!-- 弹出框 -->
  <a-modal v-model:open="visible" title="定时关机" width="500px" class="y-modal" okText="创建" @ok="onSubmit" @cancel="onCancel">
    <a-card>
      <a-row align="middle">
        <a-col :span="16">
          <a-space>
            <a-button type="link" class="y-btn" @click="openTianJiaGuanJiRenWuModal">
              <template #icon>
                <plus-outlined />
              </template>
              添加关机任务
            </a-button>
            <!-- 弹窗 - 添加关机任务 -->
            <tianJiaGuanJiRenWuModal v-model:visible="visibleTianJiaGuanJiRenWuModal"></tianJiaGuanJiRenWuModal>
          </a-space>
        </a-col>
        <a-col :span="8">
          <a-input v-model:value="searchValue">
            <template #addonBefore>
              <search-outlined /> 搜索:
            </template>
          </a-input>
        </a-col>
      </a-row>
      <a-table bordered :data-source="dataSource" :columns="columns" class="y-table" :pagination="pagination">
      </a-table>
    </a-card>
  </a-modal>
</template>

<script setup>
import tianJiaGuanJiRenWuModal from './tianJiaGuanJiRenWuModal.vue'
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  }
})

const { visible } = toRefs(props)

// 定义组件的事件
const emits = defineEmits(['update:visible'])

const visibleTianJiaGuanJiRenWuModal = ref(false)

const openTianJiaGuanJiRenWuModal = () => {
  visibleTianJiaGuanJiRenWuModal.value = true
}

const searchValue = ref('')

// 表格列
const columns = ref([
  {
    title: '编号',
    dataIndex: 'code',
    key: 'code',
    align: 'center',
    sorter: {
      compare: (a, b) => a.code.localeCompare(b.code),
      multiple: 1
    }
  },
  {
    title: '控制器',
    dataIndex: 'kongZhiQi',
    key: 'kongZhiQi',
    align: 'center',
    sorter: {
      compare: (a, b) => a.kongZhiQi.localeCompare(b.kongZhiQi),
      multiple: 2
    }
  },
  {
    title: '关机时间',
    dataIndex: 'guanJiShiJian',
    key: 'guanJiShiJian',
    align: 'center',
    sorter: {
      compare: (a, b) => a.guanJiShiJian.localeCompare(b.guanJiShiJian),
      multiple: 3
    }
  }
])

// 表格数据
const dataSource = ref([
  {
    code: '1',
    kongZhiQi: '1',
    guanJiShiJian: '1'
  }
])

// 分页
const pagination = {
  current: 1,
  pageSize: 10,
  showQuickJumper: true,
  showSizeChanger: true,
  total: 0,
  showTotal: (total, range) => {
    return `${range[0]}-${range[1]} 共 ${total} 条数据`
  },
  onChange: (page, pageSize) => {
    console.log('定时关机 > 分页改变>>', page, pageSize)
  }
}

const onSubmit = () => {
  console.log('定时关机>>')
  onCancel()
}

const onCancel = () => {
  // 触发自定义事件来通知父组件关闭弹窗
  emits('update:visible', false)
}
</script>

<style scoped>
.ant-row {
  margin-bottom: 10px;
}
</style>